package com.market.domain;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.faces.context.FacesContext;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "useractivityrecord")
public class UserActivityRecord extends BaseObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1167933126272530852L;
	
	
	public enum TYPE {LOG_IN, ACTIVATION_LOG_IN, LOG_IN_SUCCEED, LOG_IN_FAILED,LOG_OUT;
		
		private String getMessage(String key) {
			Locale locale = FacesContext.getCurrentInstance().getViewRoot()
					.getLocale();
			java.util.ResourceBundle resBundle = ResourceBundle.getBundle(
					"com.market.messages", locale);
			return resBundle.getString(key);
		}

		public String getLabel() {
			return this.getMessage("USER_ACTIVITY_RECORD_TYPE_" + this.toString());
		}
	}
	
	@Override
	public boolean equalsId(Object o) {
		if (o instanceof UserActivityRecord
				&& ((UserActivityRecord) o).getId().equals(this.id)) {
			return true;
		}
		return false;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id = 0L;	
	@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
	private java.util.Date recordDate;
	@Enumerated(EnumType.STRING)
	private TYPE type = TYPE.LOG_IN;
	@Column(length = 500)
	private String comments;
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public java.util.Date getRecordDate() {
		return recordDate;
	}
	public void setRecordDate(java.util.Date recordDate) {
		this.recordDate = recordDate;
	}
	public TYPE getType() {
		return type;
	}
	public void setType(TYPE type) {
		this.type = type;
	}
	public String getComments() {
		return comments;
	}
	public void setComments(String comments) {
		this.comments = comments;
	}
	@Override
	public String toString() {
		return "UserActivityRecord [id=" + id + ", recordDate=" + recordDate
				+ ", type=" + type + ", comments=" + comments + "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((comments == null) ? 0 : comments.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((recordDate == null) ? 0 : recordDate.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserActivityRecord other = (UserActivityRecord) obj;
		if (comments == null) {
			if (other.comments != null)
				return false;
		} else if (!comments.equals(other.comments))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (recordDate == null) {
			if (other.recordDate != null)
				return false;
		} else if (!recordDate.equals(other.recordDate))
			return false;
		if (type != other.type)
			return false;
		return true;
	}
	
	

}
